package com.ptmall.app;


import com.ptmall.app.bean.model.db.Account;
import com.ptmall.app.bean.model.db.DBHelper;
import com.ptmall.app.bean.model.db.dao.AccountDao;

/**
 * Created by Administrator on 2018/5/9.
 */

public class AccountManager {

    private static AccountManager INSTANCE;

    private AccountManager() {
    }

    public static synchronized AccountManager getInstance() {
        if (null != INSTANCE) {
            return INSTANCE;
        }
        INSTANCE = new AccountManager();
        return INSTANCE;
    }

    private Account mAccount = null;//当前登录用户

    public Account getAccount() {
        if (null == mAccount) {
            mAccount = getCurrentAccount();
        }
        return mAccount;
    }

    private AccountDao mAccountDao = DBHelper.getInstance().getAccountDao();

    public Account getCurrentAccount() {
        try {
            return mAccountDao.queryBuilder().where(AccountDao.Properties.Current.eq("1")).build().forCurrentThread().unique();
        } catch (Exception e1) {
            return null;
        }
    }

}
